package leetcode.stack_queue;

import java.util.ArrayDeque;

public class MyQueue {

    ArrayDeque<Integer> in;
    ArrayDeque<Integer> out;

    public MyQueue() {
        in = new ArrayDeque<>();
        out = new ArrayDeque<>();
    }

    public void push(int x) {
        while (!out.isEmpty()) {
            in.push(out.pop());
        }
        in.push(x);
    }

    public int pop() {
        while (!in.isEmpty())
            out.push(in.pop());
        return out.pop();
    }

    public int peek() {
        while (!in.isEmpty())
            out.push(in.poll());
        return out.peek();
    }

    public boolean empty() {
        return in.isEmpty() && out.isEmpty();
    }



}
